﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;

namespace Xiaozilang_Ordering_System
{
    public partial class losepwd : Form
    {
        public static string Number1;
       
        public losepwd()
        {
            InitializeComponent();
            textBox1.Enter += new EventHandler(textBox1_Enter);
            textBox1.Leave += new EventHandler(textBox1_leave);
            textBox2.Enter += new EventHandler(textBox2_Enter);
            textBox2.Leave += new EventHandler(textBox2_leave);

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        private void textBox1_Enter(object sender,EventArgs e) 
        {

            if (textBox1.Text == "手机账号")
            {
                textBox1.Text = "";
            }
        }
        private void textBox1_leave(object sender, EventArgs e) 
        {
            if (textBox1.Text == "") 
            {
                textBox1.Text = "手机账号";
            }
        }
        private void textBox2_leave(object sender, EventArgs e)
        {
            if (textBox2.Text=="")
            {
                textBox2.Text = "身份证号";
                
            }
        }
        private void textBox2_Enter(object sender, EventArgs e)
        {
            if (textBox2.Text == "身份证号")
            {
                textBox2.Text = "";
            }
        }
        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlDataReader reader = null;
            string tel = null;
            string number = null;
            String Judge = "0";
            try
            {
                //商家验证
                if (radioButton1.Checked)
            {
                Judge = "0";
                string sql = "select * from Business where BStel='" + textBox1.Text + "'and BSIDcar='"+textBox2 .Text+"'";
                reader = DBHelper.Select(sql);
                while (reader.Read())
                {
                    tel = reader["BStel"].ToString();
                    number = reader["BSIDcar"].ToString();
                }
                
            }
                //客户验证
            if (radioButton2.Checked)
            {
                Judge = "1";
                string sql = "select * from User1 where UStel='" + textBox1.Text + "'and USIDcar='"+textBox2.Text+"'";
                reader = DBHelper.Select(sql);
                while (reader.Read())
                {
                    tel = reader["UStel"].ToString();
                    number = reader["USIDcar"].ToString();
                }
            }
                reader.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("不明原因错误",ex.Message);
            }
            //检验用户是否存在
            if (tel == textBox1.Text&&number==textBox2.Text)
            {
                Number1 = textBox1.Text;

                this.Close();
                losepwd2 los = new losepwd2();
                los.Show();
                this.Close();
                
            }
            else 
            {
                MessageBox.Show("手机账号/身份证号错误");
            }
        }

        private void losepwd_Load(object sender, EventArgs e)
        {
            radioButton1.BackColor = Color.Transparent;
            radioButton2.BackColor = Color.Transparent;
            label1.BackColor = Color.Transparent;
            label2.BackColor = Color.Transparent;
        }
    }
}
